<template>
  <div>
    <h5 class="text-muted">当前任务：项目复核</h5>
    <el-form class="query-table-form" @submit.native.prevent :inline="true" :model="params">
      <el-form-item>
        <el-input
          v-model="params.customer_name"
          placeholder="企业名称查询"
          :clearable="true"
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="params.lender_idcard"
          placeholder="身份证号码查询"
          :clearable="true"
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="params.corp_name"
          placeholder="经营者名称查询"
          :clearable="true"
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-checkbox
          v-model="params.has_ele_fee"
          border
          :true-label="1"
          :false-label="0"
          @change="getData()"
        >
          电表
        </el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="getData()">查询</el-button>
      </el-form-item>
    </el-form>

    <c-table border class="table-sm" v-loading="loading" :columns="tableColumns" :data="tableData">
      <template v-slot:address="scope">
        <div class="text-truncate" :title="scope.row.address">{{ scope.row.address }}</div>
      </template>

      <template v-slot:status="scope">
        <div
          class="badge"
          :title="+scope.row.res_status === 2 ? scope.row.res_fail_reason : scope.row.res_option"
          :class="`badge-${scope.row.statusStyle}`"
        >
          {{ scope.row.statusLabel }}
        </div>
      </template>
    </c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <!-- 数字信用档案 -->
    <el-dialog
      :visible.sync="reportVisible"
      :close-on-click-modal="false"
      append-to-body
      top="30px"
      width="80%"
    >
      <!--<el-tabs>-->
      <!--<el-tab-pane label="数字档案">-->
      <!--<credit-file :view-mode="true"-->
      <!--:query-id="queryId"></credit-file>-->
      <!--</el-tab-pane>-->
      <!--</el-tabs>-->
      <industry-credit :oneIndustry="reportInfo"></industry-credit>
    </el-dialog>

    <!-- 复核 -->
    <review-file-dialog
      :visible.sync="editVisible"
      :related-data="editRow"
      @success="handleFileSuccess"
    ></review-file-dialog>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
// import CreditFile from '@/credit/components/creditFile/Index'
import ReviewFileDialog from '@/credit/views/county/mission/ReviewFileDialog'
// import {
//   enumOrgClass,
//   enumFarmType
// } from '@/credit/plugins/enum'
import { enumReApproval } from '@/gov/plugins/enum'
import IndustryCredit from '@/bank/components/IndustryCredit'
const enumStatusStyle = {
  0: 'info',
  1: 'success',
  2: 'danger',
}

export default {
  components: {
    // CreditFile,
    ReviewFileDialog,
    IndustryCredit,
  },
  props: {},
  data() {
    return {
      params: {
        index: 1,
        size: 10,
        lender_idcard: '',
        customer_name: '',
        corp_name: '',
        'is_approval.eq': 1,
        'service_id.eq': '',
      },
      loading: false,

      tableName: 'datum_ent_snapshot_import_view',
      tableData: [],
      totalCount: 0,
      tableColumns: [
        { attrs: { label: '推荐企业', prop: 'agr_chain_name' } },
        {
          attrs: { label: '主体名称', prop: 'customer_name', minWidth: '120px', align: 'center' },
          process: (v, row) => ({
            attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
          }),
        },
        { attrs: { label: '地址', prop: 'address' }, slot: 'address' },
        {
          attrs: { label: '客户类型', prop: 'org_class_name', align: 'center' },
          process: v => v || '-',
        },
        {
          attrs: { label: '客户行业分类', prop: 'category_name', align: 'center' },
          process: v => v || '-',
        },
        { attrs: { label: '联系电话', prop: 'corp_phone', align: 'center' } },
        { attrs: { label: '贷款金额/拟担保金额（万元）', prop: 'left_funds', align: 'center' } },
        { attrs: { label: '担保年限（年）', prop: 'warranty_period', align: 'center' } },
        { attrs: { label: '项目状态', prop: 'statusLabel', align: 'center' }, slot: 'status' },
        {
          attrs: { label: '操作', align: 'center' },
          operations: [
            {
              content: '审核',
              icon: 'fa fa-edit',
              event: this.handleEdit,
              ifRender: row => {
                return +row.res_status === 0
              },
            },
            { content: '数字信用档案', icon: 'fa fa-file-text', event: this.handleView },
          ],
        },
      ],

      // 信用档案
      // queryId: '',
      reportInfo: {},
      reportVisible: false,

      // 复核
      editVisible: false,
      editRow: {},
    }
  },
  computed: {
    ...mapGetters(['user', 'userId', 'clientId', 'job']),
    isManager() {
      return ['org_credit_super', 'org_c_manage', 'org_r_emp', 'org_r_manage', 'org_corp'].includes(
        this.job
      )
    },
  },
  watch: {
    $route(route) {
      if (route.name === 'qydReview') {
        this.getData()
      }
    },
  },
  created() {
    this.params['service_id.eq'] = this.clientId
    this.getData()
  },
  mounted() {},
  methods: {
    async getData(index = 1) {
      this.params.index = index
      const params = { ...this.params }
      const status = this.$route.query.status
      if (status !== undefined) {
        params['res_status.eq'] = status
      }
      if (!this.isManager) {
        params['orWhere.res_a.eq'] = this.userId
        params['orWhere.res_b.eq'] = this.userId
      }

      this.loading = true
      const [res] = await this.$utils.promise(
        this.$api.getData(this.$serviceName, this.tableName, params, {
          create_time: 'desc',
        })
      )
      this.loading = false

      const data = (res && res.data) || {}
      this.totalCount = data.totalCount
      this.tableData = (data.data || []).map(item => {
        item.statusLabel = enumReApproval[item.res_status] || '-'
        item.statusStyle = enumStatusStyle[item.res_status] || ''
        return item
      })
    },
    handleEdit(row) {
      this.editRow = row
      this.editVisible = true
    },
    handleView(row) {
      // this.queryId = row.customer_related_id
      this.reportInfo = row
      this.reportVisible = true
    },
    handleFileSuccess() {
      this.$store.dispatch('taskCountQyd')
      this.getData(this.params.index)
    },
  },
}
</script>
<style lang="scss" scoped></style>
